package com.orange.notificationsummary.loader;

import java.util.Collections;
import java.util.List;

import android.graphics.drawable.Drawable;

import com.orange.homescreen.pil.NotificationSummaryInterface;
import com.orange.homescreen.pil.PILInterfaceManager;
import com.orange.notificationsummary.EventTypeAndCount;
import com.orange.notificationsummary.R;
import com.orange.notificationsummary.SummaryActivity;
import com.orange.notificationsummary.event.pil.defaultimpl.BaseEvent;
import com.orange.notificationsummary.utils.LogHelper;

public class VoiceMailLoader extends BasicLoader {
	private static final String	TAG	= "VoiceMailLoader";

	private SummaryActivity		mHostActivity;
	private List<BaseEvent>		mEventList;

	public VoiceMailLoader(SummaryActivity hostActivity) {
		super(TAG, LoaderController.VOICEMAIL_LOADER);
		this.mHostActivity = hostActivity;
	}

	@Override
	protected void loadData() {
		NotificationSummaryInterface mInterface = (NotificationSummaryInterface) PILInterfaceManager
				.getInterface(NotificationSummaryInterface.class);

		this.mEventList = mInterface.getVoiceMailList(mHostActivity);
		if (mEventList != null) {
			LogHelper.d(TAG, "loadData. mEventList: " + mEventList.size());
		}
	}

	@Override
	protected void showData() {
		LogHelper.i(TAG, "showData. ");
		this.mHostActivity.setEventData(mEventList,
				this.getEventTypeAndCount(), this.getLoaderType());
	}

	@Override
	protected EventTypeAndCount getEventTypeAndCount() {
		Drawable vvmIcon = mHostActivity.getResources().getDrawable(
				R.drawable.icon_voicemail_24);
		int event_count = 0;
		long event_lasttime = 0;

		if (mEventList != null && !mEventList.isEmpty()) {
			Collections.sort(mEventList);
			event_count = mEventList.size();
			event_lasttime = mEventList.get(0).event_date;
		}

		EventTypeAndCount event = new EventTypeAndCount(event_lasttime,
				vvmIcon, event_count, mHostActivity);
		return event;

		/*
		 * int event_count = 0; long event_lasttime = 0; if (mEventList != null)
		 * { event_count = mEventList.size(); } if (event_count > 0) { if
		 * (mEventList != null) Collections.sort(mEventList); event_lasttime =
		 * mEventList.get(0).event_date; } EventTypeAndCount evnet = new
		 * EventTypeAndCount(event_lasttime, mHostActivity
		 * .getResources().getDrawable(R.drawable.icon_voicemail_24),
		 * event_count, mHostActivity); return evnet;
		 */}
}